package com.zhentao.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhentao.dtos.Result;
import com.zhentao.mapper.CategoryBrandMapper;
import com.zhentao.model.dto.product.CategoryBrandDto;
import com.zhentao.model.entity.product.Brand;
import com.zhentao.pojo.CategoryBrand;
import com.zhentao.service.CategoryBrandService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author 20183
* @description 针对表【category_brand(分类品牌)】的数据库操作Service实现
* @createDate 2024-08-19 15:43:18
*/
@Service
public class CategoryBrandServiceImpl extends ServiceImpl<CategoryBrandMapper, CategoryBrand>
    implements CategoryBrandService{
    @Resource
    private CategoryBrandMapper categoryBrandMapper;

//    @Override
//    public Result findByPage(CategoryBrandDto categoryBrandDto) {
//        PageHelper.startPage(categoryBrandDto.getPage(),categoryBrandDto.getLimit());
//
//        List<CategoryBrand> categoryBrandList = categoryBrandMapper.findByPage(categoryBrandDto);
//
//        PageInfo<CategoryBrand> categoryBrandPageInfo = new PageInfo<>(categoryBrandList);
//        return Result.success().put("data",categoryBrandPageInfo).put("total",categoryBrandPageInfo.getTotal());
//    }

    @Override
    public Result deleteById(Long id) {
        categoryBrandMapper.deleteId(id);
        return Result.success();
    }

    @Override
    public PageInfo<CategoryBrand> findByPage(Integer page, Integer limit, CategoryBrandDto categoryBrandDto) {
        PageHelper.startPage(page , limit) ;
        List<CategoryBrand> categoryBrandList = categoryBrandMapper.findByPage(categoryBrandDto) ;
        return new PageInfo<>(categoryBrandList);

    }

    @Override
    public void updateId(CategoryBrand categoryBrand) {
        categoryBrandMapper.updateId(categoryBrand) ;
    }

    @Override
    public List<Brand> findBrandByCategoryId(Long categoryId) {
        return categoryBrandMapper.findBrandByCategoryId(categoryId);
    }
}




